package cn.silver.module.system.domain;

import cn.silver.framework.mybatis.annotation.Table;
import cn.silver.framework.mybatis.annotation.TableField;
import cn.silver.framework.mybatis.domain.BaseEntity;
import cn.silver.framework.mybatis.enums.SearchEnums;
import cn.silver.framework.satoken.model.LoginUser;
import cn.silver.framework.satoken.utils.LoginHelper;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.io.Serial;
import java.io.Serializable;

/**
 * 常用网址对象 sys_user_website
 *
 * @author Silver.Zhou
 */

@Data
@NoArgsConstructor
@Table(name = "sys_website")
@EqualsAndHashCode(callSuper = true)
@Schema(name = "SysWebsite", description = "常用网址对象")
public class SysWebsite extends BaseEntity implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;
    /**
     * 用户信息
     */
    @Schema(title = "用户信息")
    @TableField(name = "user_id", searchType = SearchEnums.EQ)
    private String userId;

    /**
     * 网址名称
     */
    @Schema(title = "网址名称")
    @TableField(name = "name", searchType = SearchEnums.LIKE)
    private String name;

    /**
     * 访问地址
     */
    @Schema(title = "访问地址")
    @TableField(name = "link", searchType = SearchEnums.EQ)
    private String link;

    @Schema(title = "图标")
    @TableField(name = "img", searchType = SearchEnums.EQ)
    private String img;

    /**
     * 排序
     */
    @Schema(title = "排序")
    @TableField(name = "sort", searchType = SearchEnums.EQ)
    private Integer sort;
    private String remark;

    @Override
    public void preInsert() {
        super.preInsert();
        LoginUser user = LoginHelper.getLoginUser();
        if (user != null) {
            this.userId = user.getId();
        }
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("id", getId())
                .append("userId", getUserId())
                .append("name", getName())
                .append("addr", getLink())
                .append("sort", getSort())
                .toString();
    }
}
